/**
 * Created by apple on 16/4/28.
 */
"use strict";

class Interceptor {
    constructor($q, $rootScope ) {
        "ngInject"

        return {
            request : (config) => {
                return config;
            },
            response : (response) => {
                let data = response.data;
                if (data) {

                    if (data.resultCode === '403') {
                        $rootScope.$emit("unauthorized");
                        return $q.reject(response)
                    }

                    if (data.resultCode === '409') {
                        $rootScope.$emit("empty.post");
                        return $q.reject(response)
                    }

                }
                return $q.resolve(response);
            },
            responseError : (response) => {
                return $q.reject(response)
            }
        }
    }
    static factory ($q, $rootScope, $cookies) {
        "ngInject"
        return new Interceptor($q, $rootScope, $cookies)
    }
}

export default Interceptor;